package letcode3

import (
	"math"
	"strings"
)

func LengthOfLongestSubstring(s string) int {
	hashMap := map[string]int{}
	left, ans := 0, math.MinInt

	ss := strings.Split(s, "")
	for right, value := range ss {
		hashMap[value] += 1
		for hashMap[value] > 1 {
			hashMap[ss[left]] -= 1
			left++
		}
		ans = max(ans, right-left+1)
	}
	return ans
}
